/**
 * Copyright (c) 时间, Tal.Ben 袁东昊 (ydonghao2@gmail.com).
 *
 * 版权
 */
package com.talben.soudian.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import butterknife.InjectView;

import com.talben.soudian.AppContext;
import com.talben.soudian.R;
import com.talben.soudian.TDevice;
import com.talben.soudian.base.BaseActivity;
import com.talben.soudian.bean.SimpleBackPage;

/**
 * @Title: ShowWebActivity.java
 * @Package com.talben.soudian.ui
 * @Description: 显示网络
 * @author Tal.Ben
 * @date 2015年6月27日 上午10:06:12
 * @version v1.0
 */
public class ShowWebActivity extends BaseActivity{
	
	public final static String BUNDLE_KEY_WEB_PAGE = "BUNDLE_KEY_WEB_PAGE";

	@InjectView(R.id.wb_all)
	WebView mWebChinaPost;
	
	@Override
    protected int getLayoutId() {
        return R.layout.activity_web_view;
    }
    
    @Override
    protected boolean hasBackButton() {
        return true;
    }

	@Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        initFromIntent(getIntent());
    }

    protected void initFromIntent(Intent data) {
        if (data == null) {
            throw new RuntimeException(
                    "you must provide a page info to display");
        }
        
        String title = data.getStringExtra("title");
        if (title != null) {
        	setActionBarTitle(title);
		}
     
        String showUrl = data.getStringExtra("showUrl");
        if (showUrl != null) {
        	if (!TDevice.isNetworkReady(getApplicationContext())) {
                AppContext.showToastShort(R.string.tip_no_internet);
            } else {
            	mWebChinaPost.getSettings().setBuiltInZoomControls(true);
                mWebChinaPost.loadUrl(showUrl);  
                mWebChinaPost.setWebViewClient(new WebViewClient(){  
        	        @Override  
        	        public boolean shouldOverrideUrlLoading(WebView view, String url) {  
        	            // TODO Auto-generated method stub  
        	            view.loadUrl(url);// 使用当前WebView处理跳转  
        	            return true;//true表示此事件在此处被处理，不需要再广播  
        	        }  
        	        @Override   //转向错误时的处理  
        	        public void onReceivedError(WebView view, int errorCode,  
        	            String description, String failingUrl) {  
        	        }
                });
            }
		}
    }


    @Override
    public void onClick(View v) {}

    @Override
    public void initView() {}

    @Override
    public void initData() {}
	
}

